package com.example.demo.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <pre>
 *  描述:
 * </pre>
 *
 * @author godelgnis(wujiaer)
 * @version 1.0.0
 * @date 2022/5/5 14:16
 */
public class RedisTest {
    private static JedisPool pool;
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(50);
        config.setMaxWaitMillis(3000);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        pool = new JedisPool(config, "192.168.54.23", 6379, 1000, "bfdbfd5435", 8);
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(8);
        for (int j = 0; j < 100; j++) {
            final int x =j;
            executorService.submit(()->{
                Jedis jedis = pool.getResource();
                for (int i = 100000 * x; i < 100000 * (x + 1); i++) {
                    jedis.set("key" + i, String.valueOf(i));
                }
                System.out.println("完成 x=" + x);
            });
        }
    }

}
